﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CarLeasing.Models;

namespace CarLeasing.Forms.Controls
{
    public partial class CarInfoList : UserControl
    {
        public CarInfoList()
        {
            InitializeComponent();
        }


        public void LoadCarInfos(CarInfo[] carInfos)
        {
            listBox.Items.Clear();
            listBox.Items.AddRange(carInfos);
        }

        private void listBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selectedCar = listBox.SelectedItem as CarInfo;
            CarSelected?.Invoke(selectedCar);
        }

        public event Action<CarInfo> CarSelected;
    }
}
